package www.xudan.android_ffmpeg.videoplayer.widget.status;

import android.media.MediaPlayer;
import android.view.View;


import tv.danmaku.ijk.media.player.IMediaPlayer;
import www.xudan.android_ffmpeg.R;
import www.xudan.android_ffmpeg.videoplayer.widget.BasePlayerView;

public class InitingStatus extends BaseStatus {
    public InitingStatus(BasePlayerView view) {
        super(view);
    }

    boolean isBack;

    @Override
    public void play() {

    }

    @Override
    public void error() {
        view.player.stop();
        view.iv_screen_play.setImageResource(R.drawable.error);
        view.iv_screen_play.setVisibility(View.VISIBLE);
        view.removeLoading();
        view.setStatus(view.error);
    }

    @Override
    public void completed() {

    }

    @Override
    public void onInfo(IMediaPlayer iMediaPlayer, int what, int i1) {
        if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END) {
            view.setStatus(view.playing);
            view.removeLoading();
        }
    }

    @Override
    public void netChange() {

    }

    @Override
    public void onBack() {
        isBack = true;
    }

    @Override
    public void onStart() {
        isBack = false;
    }

    @Override
    public void pause() {
        view.player.pause();
        view.setStatus(view.pause);
    }

    @Override
    public void copyStatusToChild(BasePlayerView view) {
        view.setStatus(view.initing);
    }

    @Override
    public void onPrepared(IMediaPlayer iMediaPlayer) {
        super.onPrepared(iMediaPlayer);
        if (isBack) {
            view.player.pause();
            view.setStatus(view.pause);
        } else {
            view.player.start();
            view.startProgressTimer();
            view.setStatus(view.playing);
            if (view.getVideoModel().playFromLastposition && view.playTime > 0) {
                view.player.seekTo(view.playTime);
            } else {
                view.removeLoading();
            }
        }
    }
}
